package cn.itcast.web.controller;

import cn.itcast.domain.system.User;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class BaseController {
    //用来加载与对象
    protected HttpServletRequest request;
    protected HttpServletResponse response;
    protected HttpSession session;
    protected Model model;

    /*
        @ModelAttribute
              配置到方法上， 在执行此控制器所有方法之前执行的方法
              返回值为空 ： void
              参数 ： 配置参数规则和控制器方法一模一样
     */
    @ModelAttribute
    public void init(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model) {
        this.request = request;
        this.response = response;
        this.session = session;
        this.model = model;
    }

    /*
        获取当前登录用户的企业id
     */
    protected String getLoginCompanyId(){
        //模拟企业id
        return "1";
    }

    /*
        获取当前登录用户的企业名称
     */
    protected String getLoginCompanyName(){
        //模拟企业name = "传智播客"
        return "传智播客";
    }

    /**
     * 获取登录用户
      */
    protected User getLoginUser(){
        return (User)session.getAttribute("loginUser");
    }

}
